package com.bi.bitest.bao.Client;

import android.util.Log;
import com.bi.bitest.bao.UrlPath;
import com.bi.bitest.bao.utils.HttpTools;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

/**
 * Created
 * Author:bi[FR]
 * Date:15-10-20
 */
public class ClientAPI {
    /**
     * 单独提取服务器头网址 防止以后服务器更改
     */
    private static final String API_POINT="http://mobile.ximalaya.com";
    private ClientAPI(){

    }

//-------------------------接口18
    public static JSONObject getAlbum_Play(String id){
        JSONObject ret=null;
        String []path=UrlPath.path18.split("%s");

        String pathNew=path[0]+id;

        byte[]data=HttpTools.doGet(pathNew);
        if(data!=null){
            try {
                String str=new String (data,"UTF-8");
                ret=new JSONObject(str);
                Log.d("json","------>"+ret);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }


    //--------------------接口17
    public static JSONObject getAlbum_AlbumDetail(long id){
        JSONObject ret=null;
        String []path=UrlPath.path17.split("%s");

        String pathNew=path[0]+String.valueOf(id)+path[1]+String.valueOf(id)+path[2];

        byte[]data=HttpTools.doGet(pathNew);
        if(data!=null){
            try {
                String str=new String (data,"UTF-8");
                ret=new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

        //-----------------接口12
    /**
     * 获取发现分类
     * API地址：/mobile/discovery/v1/categories?device=android&picVersion=10&scale=2
     */
    public static JSONObject getDiscoverCategories(){
        JSONObject ret=null;
        byte[]data=HttpTools.doGet(API_POINT+"/mobile/discovery/v1/categories?device=android&picVersion=10&scale=2");
       if(data!=null){
           try {
               String str=new String (data,"UTF-8");
              ret=new JSONObject(str);
           } catch (UnsupportedEncodingException e) {
               e.printStackTrace();
           } catch (JSONException e) {
               e.printStackTrace();
           }
       }
        return ret;
    }

    //------------------接口11

    /**
     * 请求网址 /mobile/discovery/v1/recommends
     * ?channel=and-f6&device=android&includeActivity=true
     * &includeSpecial=true&scale=2&version=4.1.7.1
     * @param channel
     * @param includeActivity
     * @param includeSpecial
     * @return
     */
    public static JSONObject getDiscoverRecommend(
            String channel,boolean includeActivity,
            boolean includeSpecial){
        JSONObject ret=null;
        if(channel==null){
            channel="and-f6";
        }

        String url=API_POINT+"/mobile/discovery/v1/recommends"
                +"?channel="+channel
                +"&device=android"
                +"&includeActivity="+includeActivity
                +"&includeSpecial="+includeSpecial
                +"&scale=2"
                +"&version=4.1.7.1";
        byte[]data=HttpTools.doGet(url);

        if(data!=null){
            try {
              String str=new String(data,"utf-8");
                ret=new JSONObject(str);


            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

        return ret;

    }

}
